﻿/*************************************************
 * 
 *  框架级
 *  
 *  数据库通用类 - 执行分页查询
 * 
 *  create by ternence
 * 
 *  create datetime at 2017-03-17
 *  
 *  西安佳卓信息科技有限公司 ©2017
 * 
 * ***********************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Dapper;


namespace Zor_IDAL
{
    public class DapperPage<T> where T : class 
    {
        /// <summary>
        /// 分页通用函数
        /// </summary>
        /// <param name="pages">分页对象</param>
        /// <param name="TotalCount">返回参数</param>
        /// <returns></returns>
        public static List<T> PageList(BasePager pages,out int TotalCount)
        {
            var param = new DynamicParameters();
            param.Add("@@PageSize", pages.PageSize);
            param.Add("@CurrentCount", pages.CurrentCount);
            param.Add("@TableName",pages.TableName);
            param.Add("@Where",pages.Where);
            param.Add("@Order",pages.Order);
            param.Add("@TotalCount",0,DbType.Int32,ParameterDirection.Output);

            using (IDbConnection conn = DapperConn.OpenSqlConnection())
            {
               List<T> lstT = conn.Query<T>("ZorPager", param, null, true, null, CommandType.StoredProcedure).ToList();
               TotalCount = (int)param.Get<object>("@TotalCount");
               return lstT;
            }
            
        }


  


    }
}
